#include "applicationinstallui.h"
#include "ui_applicationinstallui.h"
#include <optra/common/proxy.h>
#include "zonesmanager.h"
#include <optra/common/db.h>
#include <optrzone.h>
#include "applicationsmanager.h"
O_Z

        extern Optra::Proxy* proxy;
extern ApplicationsManager* appmanager;

ApplicationInstallUi::ApplicationInstallUi(QWidget *parent) :
    GuiWindow(parent),
    ui(new Ui::ApplicationInstallUi)
{
    ui->setupUi(this);
    connect(ui->installApplication, SIGNAL(clicked()), SLOT(installClicked()));

}



void ApplicationInstallUi::setup()
{
    model_ = new QSqlTableModel(0, OZ->db()->db());
    model_->setTable("applications");
    ui->applicationList->setModel(model_ );
}


void ApplicationInstallUi::installClicked()
{
    QString fileName = QFileDialog::getOpenFileName(this,tr("Open Application"), proxy->directory(Optra::Proxy::zones).dirName(), tr("Application Files (*.dll)"));
    QFile f(fileName);
    if (f.open(QFile::ReadOnly)){
        appmanager->installApplication(&f);      
    }
    update();
}

void ApplicationInstallUi::update()
{
    model_->select();
}

void ApplicationInstallUi::beforeShow()
{

}

void ApplicationInstallUi::beforeHide()
{

}

void ApplicationInstallUi::remove()
{
    delete model_;
}

ApplicationInstallUi::~ApplicationInstallUi()
{
    delete ui;
}

void ApplicationInstallUi::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
